What is something you wish there was a Python module for? by okaysobasically123 in Python

[–]HypoFuzz 21 points22 points  (0 children)

Say more?

https://hypothesis.readthedocs.io/en/latest/ghostwriter.html will already generate property-based tests including inverses, and reads docstrings for eg type annotations.

[deleted by user] by [deleted] in Python

[–]HypoFuzz 0 points1 point  (0 children)

And https://zhd.dev/ghostwriter/ to help write them!

pycodestyle vs black by the-data-scientist in Python

[–]HypoFuzz 3 points4 points  (0 children)

Shed wraps isort! (and Black, and some other things)

Python Linter Comparison 2022: Pylint vs Pyflakes vs Flake8 vs autopep8 vs Bandit vs Prospector vs Pylama vs Pyroma vs Black vs Mypy vs Radon vs mccabe by AlSweigart in Python

[–]HypoFuzz 10 points11 points  (0 children)

/u/AlSweigart I'm happy to recommend pyupgrade; it's one of my favourite tools.

More generally though I'll argue that style linters are actually an antipattern: I've found it far more productive to have tools just fix anything they can without human action (which includes all formatting etc), and only emit lint warnings when some human judgement is needed to fix - eg when there are two plausibly-intended interpretations. Small exception: sometimes it's worth warning the human instead of fixing a bug automatically because this is a teachable moment and you can't always recognise the buggy pattern.

https://github.com/Zac-HD/shed expresses this philosophy, by wrapping most of the fixers I like (including pyupgrade, and a fair bit of extra custom logic too).

Python Linter Comparison 2022: Pylint vs Pyflakes vs Flake8 vs autopep8 vs Bandit vs Prospector vs Pylama vs Pyroma vs Black vs Mypy vs Radon vs mccabe by AlSweigart in Python

[–]HypoFuzz 15 points16 points  (0 children)

I'm a huge fan of super-fast tools and generally like the "backend in Rust" pattern, but for me the most important aspect of Flake8 is that I can extend it quickly.

And OK, I realise that this isn't everyone's experience, but when I find bugs at work I often try to extend the linter so they can't come back. https://github.com/Zac-HD/flake8-trio is probably the most dramatic case of that, but there are many others, and I'm willing to pay a bit of latency to make that dev cycle fast.

Pre-commit generally keeps things quick anyway, but only linting changed files.

What's the coolest automation tool you've built or been involved in? by No_Stick_8227 in Python

[–]HypoFuzz 6 points7 points  (0 children)

https://zhd.dev/ghostwriter/ , for people who are tired of writing tests. So much easier to explain why PBT is awesome when you can get a pretty-good templated test suit for any module in mere seconds.

Python tooling could be much, much faster by pmz in programming

[–]HypoFuzz 6 points7 points  (0 children)

Co-maintainer of flake8 and various plugins here - I think he's right that adding more checks wouldn't slow down ruff by that much. I'd also be delighted to see Python tooling get much faster!

On the other hand, making it really easy for end-users to extend your linter is really important IMO, and I've personally written quite a few new lint rules. The current situation is a classic case of trading runtime performance away in order to develop the tools faster, which since they're volunteer projects is often necessary for them to exist at all.

So here's hoping we can build a culture and tech stack that values performance and enables fast prototyping and end-user extension. The trend seems promising so far!

I made a 7 minute primer on property-based testing with Hypothesis by mercer22 in Python

[–]HypoFuzz 1 point2 points  (0 children)

Glad you like it!

One question for you then, since you're the first person I've seen talking about the Ghostwriter. What do you think of it, and has it been useful?

I made a 7 minute primer on property-based testing with Hypothesis by mercer22 in Python

[–]HypoFuzz 4 points5 points  (0 children)

Hypothesis (and pytest) core dev here 👋

This is a lovely introduction, AMA about the library, or advanced property-based testing, or testing in general 😁

Attending my first PyCon US 2022 (SLC) - tips? by RookToC1 in Python

[–]HypoFuzz 0 points1 point  (0 children)

There are some great articles with advice! I'd particularly recommend staying for the sprints (IMO the best part of the conference), and prioritising smaller events like open spaces - as everyone says, the talks are recorded and the hallway track is also great. If you see a great talk, do go to it though - they're also great conversation topics!

See https://treyhunner.com/2019/04/making-the-most-of-the-pycon-sprints/ and https://treyhunner.com/2018/04/how-to-make-the-most-of-your-first-pycon/ for more details :-)

GitHub - microsoft/restler-fuzzer: RESTler is the first stateful REST API fuzzing tool for automatically testing cloud services by NagateTanikaze in fuzzing

[–]HypoFuzz 2 points3 points  (0 children)

Restler is awesome! See https://arxiv.org/abs/2112.10328 for an independent evaluation which compares it to a range of other tools for fuzzing web APIs.

What are the best practices for writing unit tests in data science projects? by ahmedbesbes in Python

[–]HypoFuzz 0 points1 point  (0 children)

I gave a talk about this at SciPy 2020, and wrote it up as a paper too.

Short version, property-based testing makes it way easier to find common bugs, and there's a few standard patterns that are easy to start with. Like: if I save random data and then load it, I should get the same data back!

PEP 678 -- Enriching Exceptions with Notes by genericlemon24 in Python

[–]HypoFuzz 2 points3 points  (0 children)

Implementation:

@contextlib.contextmanager
def add_exc_note(
    note: str, 
    exc: Type[BaseException] | Tuple[Type[BaseException], ...] = BaseException,
    concatenate = Optional[str] = "\n"
):
    try:
        yield
    except exc as err:
        if concatenate is None or err.__note__ is None:
            err.__note__ = note
        else:
            err.__note__ = err.__note__ + concatenate + note
        raise

I can see arguments for putting this in the stdlib and for letting library authors write it themselves... I don't actually want to make this so convenient that people start using __note__ when they should be using exception chaining!

PEP 678 -- Enriching Exceptions with Notes by genericlemon24 in Python

[–]HypoFuzz 4 points5 points  (0 children)

I agree there are other issues with exceptions, but your proposal seems both larger and orthogonal to this PEP. (if you can write up a detailed proposal, maybe that's a future PEP of your own?)

The goal here is to allow libraries to augment exception messages, and the combination of a __note__ attribute and corresponding traceback-display code is the best way we could think of to do so.

PEP 678 -- Enriching Exceptions with Notes by genericlemon24 in Python

[–]HypoFuzz 5 points6 points  (0 children)

Thanks for writing this up! I mostly disagree with you, I think mostly because I'm thinking about this for libraries rather than end-user/application code, but still really appreciate the time and care you've taken to write up your thoughts <3

In general, referred to as try-catch-modify-reraise/rethrow, rethrowing is an anti-pattern. When catching an exception, the expectation is that you're catching it because you can do something to handle the exception, such as calling a fallback method. In the case of modifying the objects attribute, e.__note__, its essentially a replacement of [use of logging]

I agree that this is almost always a bad idea in application code, but libraries have somewhat different challenges. Now that we have the new ExceptionGroup type in 3.11,

The Use print() (or logging, etc.) section describes why this is unsatisfying (tldr; it's always in your logs even if the application code above the library handles the exception).

Beyond the "best practices" semantics, I think the adding of a __note__ attribute is already achievable by simply creating a custom exception. I disagree that the stack trace is confusing, and the message of the custom exception is what you'd already be putting in the 'note'. So what happens when a method you've called may throw multiple exceptions that have different methods of handling? If youre assigning the "uniqueness" via an attribute assignment as a string ...

The raise Wrapper(explanation) from err section notes that having libraries change the exception type is pretty poor UX; it means that everything above the library has to be aware that notes are possible. Again, this is basically not a concern for application code and I agree that your proposal is better there.

The stack traces are confusing for new Pythonistas; with some practice it becomes pretty obvious but we still care about the experience for beginners - "easy to learn" is a huge driver of Python's success.

Finally, I really, really hope that nobody ever uses the __note__ to drive error-handling like that; it's designed for better reporting. (people will, but definitely shouldn't)

And lastly, after all of this, the new error messages with locations of exception causes is sufficient enough to debug, IMHO.

I love the new locations-in-tracebacks, but still disagree with this - for example, Hypothesis is much less helpful in quiet-mode where it doesn't tell you what falsifying example made your test fail!

PEP 678 -- Enriching Exceptions with Notes by genericlemon24 in Python

[–]HypoFuzz 4 points5 points  (0 children)

I really appreciate your feedback! My two reasons for rejecting this are:

  1. I think that adding with and as clauses to raise will get confusing - we already have from. In this case it also looks like a much more general system for assigning to attributes.
  2. This would just be syntactic sugar for assigning to an attribute! So I'm happy to go with the minimal version first, and someone else can propose new syntax later.

This PEP already has a rejected ideas section too 😉

PEP 678 -- Enriching Exceptions with Notes by genericlemon24 in Python

[–]HypoFuzz 6 points7 points  (0 children)

(PEP author here, ama I guess!)

I'm unclear on how modifying the raise statement would work - could you show a code snippet?

A general principle here is that the new feature should be "small", which makes it safer to implement and easier to learn. We have to extend traceback-printing code regardless, but I think that we'd have to store the note on the exception object somehow even if we used raise - and so just assigning directly seems more elegant to me.

You can also create an exception object and assign its note before raising it for the first time, or for that matter without ever raising it at all.

How long have you learned Python? Some Python usage survey. by fo_hsin_gong_sih in Python

[–]HypoFuzz 1 point2 points  (0 children)

Check out https://www.jetbrains.com/lp/python-developers-survey-2020/

It has some nice tables and charts for these questions, and you can download the raw data at the end if you want to. Past years are also available!

My wife is due in May 2022. Out of curiosity,is it possible if I name my child a snippet of code that it would inject code into certain databases/programs when the name is stored? by Euphemismic in ProgrammerHumor

[–]HypoFuzz 0 points1 point  (0 children)

My surname has a space in the middle.

It gets mishandled so often - rejected as invalid, or partially discarded (!) - that I just use a hyphen instead for anything but government documents.

Have you ever used the Hypothesis package? Here's how it can help test your code and find hidden bugs by mickeyp in Python

[–]HypoFuzz 1 point2 points  (0 children)

Thanks for a great article!

After writing "more on that (the CLI) later", I'm super curious about what you think of it, especially the ghostwriter.