Skip to content

mriley-cardinal/pywrong

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 

Repository files navigation

pywrong

Because if it walks like a duck and quacks like a duck, you don't need to DECLARE that it's a duck.

pywrong is a Python "linter" that enforces duck typing by finding and shaming all type hints in your code.

    __
___( o)>
\ <_. )
 `---'  QUACK! Your code has been found GUILTY of type hinting!

Why?

Python is a dynamically typed language. Variables can be anything. They contain multitudes. Why constrain them with your bourgeois "type annotations"?

Every time you write def foo(x: int) -> str:, a duck somewhere loses its quack.

Installation

# Clone this repository
git clone https://github.com/mriley-cardinal/pywrong.git

# That's it. No pip install. No dependencies.
# Just pure, untyped Python.

Usage

# Scan a single file
python pywrong.py myfile.py

# Scan a directory
python pywrong.py src/

# Scan current directory
python pywrong.py .

Example Output

    __
___( o)>
\ <_. )
 `---'  QUACK! Your code has been found GUILTY of type hinting!

Scanning for type hint violations...

======================================================================
VIOLATIONS DETECTED
======================================================================

src/utils.py:12
  Parameter 'name: str'? Just accept ANYTHING. That's the Python way!
  >>> def greet(name: str) -> str:

src/utils.py:12
  -> str? More like -> TRUST_ME_BRO. This is Python, not TypeScript.
  >>> def greet(name: str) -> str:

src/models.py:5
  Variable 'count: int'? Python variables are FREE. Let them BE.
  >>> count: int = 0

======================================================================
3 type hints?! This code is basically Java with extra steps.
======================================================================

What It Detects

  • Return type annotations: -> int, -> str, -> List[Thing]
  • Parameter type hints: def foo(x: int, y: str):
  • Variable annotations: count: int = 0

What It Doesn't Detect (Yet)

  • Type comments (# type: ignore doesn't count, you're still guilty)
  • Generic type aliases
  • typing module imports (but we're watching you)

FAQ

Q: But type hints help with IDE autocomplete! A: Real Pythonistas read the source code.

Q: What about mypy and static analysis? A: What about FREEDOM?

Q: Isn't this just a joke? A: Quack.

Q: Should I actually use this in production? A: This linter is provided as-is. If you run it in CI and block your deploys, that's between you and the ducks.

License

MIT - Do whatever you want. Just like Python variables.

Contributing

Found a type hint pattern we're not catching? Open an issue! Let's make the ducks proud.


"In the face of ambiguity, refuse the temptation to guess." — The Zen of Python

"In the face of type hints, refuse the temptation to annotate." — The Zen of pywrong

About

You've heard of mypy, pyright, pyrefly, ty and zuban, but have you tried pywrong?

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages