Hacker Newsnew | past | comments | ask | show | jobs | submit | azkae's commentslogin

I am using macher for small edits on a codebase with gptel: https://github.com/kmontag/macher

The package define a list of tools that gptel can use to inspect and edit a project. The tools are packaged as a preset so all you have to do is add "@macher" to your prompt to include the tools & update the system directive.


You can already do this without pattern matching:

  from typing import Union, NoReturn
  
  class Foo:
      name: str
  
  class Bar:
      size: int
 
  Variant = Union[Foo, Bar]       # or `Foo | Bar` in Python 3.10
  
  def assert_never(x: NoReturn) -> NoReturn:
      # runtime error, should not happen
      raise Exception(f'Unhandled value: {x}')
  
  def tell(x: Variant):
      if isinstance(x, Foo):
          print(f'name is {x.name}')
      elif isinstance(x, Bar):
          print(f'name is {x.size}')
      else:
          assert_never(x)
mypy returns an error if you don't handle all cases.


The difference is that in Typescript, this works on any structurally matching object that you may get e.g. through JSON.


Somewhat related, if you are looking to do scripts in Python you should take a look at `sh`:

  import sh
  print(sh.ifconfig("eth0"))
https://amoffat.github.io/sh/


https://amoffat.github.io/sh/sections/faq.html

> Will Windows be supported?

> There are no plans to support Windows.


Is this the ergonomic `subprocess.Popen` alternative?


Yes this wraps subprocess.Popen in a nice API.


I use icecream [1] for the same purpose while debugging. It's really handy.

[1] https://github.com/gruns/icecream


Thanks for sharing! I like that ic includes a hook for logging, which I think is an advantage over calling print directly. I realize for a lot of examples, they’re quick and dirty but I almost always end up setting up a logger with an stderr or stdout handler so that other handlers can also send it to a file if desired. This makes it easier to run these in production on daemons and such where your code might not have an stdout to print to.


Scrolling with the trackpad seems way better by default, no more mouse-wheel-scroll-amount/mouse-wheel-progressive-speed hacks !


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: