SylvainDe / DidYouMean-Python

Module to have suggestions in case of errors (NameError, AttributeError, etc).
MIT License
122 stars 15 forks source link

More suggestions #18

Open SylvainDe opened 8 years ago

SylvainDe commented 8 years ago

Maybe things from https://twitter.com/DrapsTV/status/660657599210266624 can be reused (maybe not).

SylvainDe commented 8 years ago

A few ideas from http://migrateup.com/main-difference-python-3/ are interesting too.

SylvainDe commented 8 years ago

http://www.oreilly.com/programming/free/how-to-make-mistakes-in-python.csp /http://www.oreilly.com/programming/free/files/how-to-make-mistakes-in-python.pdf

SylvainDe commented 8 years ago

Probably worth re-reading http://stupidpythonideas.blogspot.fr/2015/05/if-you-dont-like-exceptions-you-dont.html ( and http://stupidpythonideas.blogspot.fr/2015/12/how-lookup-works.html ) when I have more time.

SylvainDe commented 8 years ago

https://github.com/mdipierro/autoinstaller : interesting idea. I'll try to understand the code and see if I can reuse ideas out of it.

Also, it could be nice to make things usable with the -m option ( http://python-packaging.readthedocs.org/en/latest/command-line-scripts.html / https://www.reddit.com/r/Python/comments/42u5dm/how_to_structure_a_module_that_is_intended_to_be/ ).

SylvainDe commented 8 years ago

https://github.com/bndr/pipreqs/blob/master/pipreqs/pipreqs.py

SylvainDe commented 8 years ago

Principle of Least Astonishment and Python : http://lucumr.pocoo.org/2011/7/9/python-and-pola/ .

A few suggestions might make sense.

SylvainDe commented 8 years ago

Confusing/interesting error messages here : https://www.reddit.com/r/Python/comments/4ivd2k/what_is_your_favorite_python_error_message/

SylvainDe commented 8 years ago

https://github.com/asweigart/pydidyoumean

SylvainDe commented 8 years ago

I've just discovered the change about literal octals in Python 3. Might be interesting to have a suggestion.

SylvainDe commented 8 years ago

https://twitter.com/raymondh/status/772957699478663169 "#python tip: What Python says: "TypeError: 'method' object is not subscriptable" What it means: "Use parentheses instead of square brackets""

https://twitter.com/raymondh/status/773224135409360896 "What #Python says: TypeError: 'Tk' object cannot be interpreted as an integer What it means: class 'Tk' does not have an index method"

SylvainDe commented 8 years ago

http://stackoverflow.com/questions/38147923/mixing-datetime-strptime-arguments/38215307 pretty common error: mixing argument of strptime.

https://twitter.com/brandon_rhodes/status/781234730091941888

SylvainDe commented 8 years ago

SyntaxError: if a = b: and if a == b

SylvainDe commented 8 years ago

https://twitter.com/cfbolz/status/783313503230844929 .

The whole twitter thread is interesting with links such as:

https://www.researchgate.net/publication/307088989_Some_Trouble_with_Transparency_An_Analysis_of_Student_Errors_with_Object-oriented_Python

https://mail.python.org/pipermail/python-ideas/2016-October/042672.html

https://github.com/ipython/ipython/pull/9073/files

Also, the corresponding commit is:

https://bitbucket.org/pypy/pypy/commits/e664458f25d07bbc8378161dcd8973df6a701b96

(includes nice tests)

SylvainDe commented 8 years ago

http://inventwithpython.com/blog/2012/07/09/16-common-python-runtime-errors/

SylvainDe commented 8 years ago
>>> 3.5 ^ 2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for ^: 'float' and 'int'
>>> 3.5 ** 2
12.25
SylvainDe commented 8 years ago
>>> raise NotImplemented
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: exceptions must be old-style classes or derived from BaseException, not NotImplementedType

A fuzzy match on the actual subclasses of BaseException could be nice :)

SylvainDe commented 7 years ago

TypeError: unhashable instance

Maybe suggest how to make the instance hashable (on custom classes), maybe suggest hashable types (frozenset, tuple, etc).

SylvainDe commented 7 years ago

https://mail.python.org/pipermail/python-ideas/2016-November/043848.html https://mail.python.org/pipermail/python-ideas/2016-December/043910.html

SylvainDe commented 7 years ago

RuntimeError: dictionary changed size during iteration

Maybe suggest ideas from : http://stackoverflow.com/questions/11941817/how-to-avoid-runtimeerror-dictionary-changed-size-during-iteration-error

SylvainDe commented 7 years ago

http://stackoverflow.com/questions/19234598/typeerror-str-object-cannot-be-interpreted-as-an-integer

http://stackoverflow.com/questions/28036309/typeerror-list-object-cannot-be-interpreted-as-an-integer

SylvainDe commented 7 years ago

https://mail.python.org/pipermail/python-checkins/2015-October/139263.html

SylvainDe commented 7 years ago

This is an interesting issue and might deserve some suggestion : http://stackoverflow.com/questions/4545661/unicodedecodeerror-when-redirecting-to-file

SylvainDe commented 7 years ago

TypeError: can only concatenate list (not "dict_keys") to list

SylvainDe commented 7 years ago

TypeError: argument to reversed() must be a sequence

SylvainDe commented 7 years ago

http://stackoverflow.com/questions/41388606/python-3-6-vs-3-5-typeerror-message-on-string-concatenation

SylvainDe commented 7 years ago

I got this issue : http://stackoverflow.com/questions/24463202/typeerror-get-takes-no-keyword-arguments . Maybe suggesting position arguments and explaining that C-level API is exception to the usual rule is a good idea.

SylvainDe commented 7 years ago

http://sametmax.com/quelques-erreurs-tordues-et-leurs-solutions-en-python/

SylvainDe commented 7 years ago

http://darkf.github.io/posts/problems-i-have-with-python.html

SylvainDe commented 7 years ago

Idea: detection (?) and suggestion for circular import.

https://fr.reddit.com/r/Python/comments/5qxhcu/could_you_take_a_look_at_my_first_ever_python/?st=iyjta9cc&sh=5cd2c314

https://github.com/bndr/pycycle

https://docs.python.org/3/faq/programming.html#how-can-i-have-modules-that-mutually-import-each-other

https://docs.python.org/3/faq/programming.html#what-are-the-best-practices-for-using-import-in-a-module

SylvainDe commented 7 years ago

Idea: reuse _moved_attributes from https://github.com/benjaminp/six/blob/master/six.py (with proper attribution).

SylvainDe commented 7 years ago

Idea: use gc.get_objects() for various purposes (get_func_by_name, get_type_by_name, etc).

SylvainDe commented 7 years ago

https://twitter.com/sam_et_max/status/836551598054731776 https://twitter.com/sam_et_max/status/836551787058454529

SylvainDe commented 7 years ago

"TypeError: 'generator' object is not subscriptable" -> itertools.islice(my_generator, 5)

SylvainDe commented 7 years ago

Set.remove keyerror set.discard

SylvainDe commented 7 years ago

Suggest using PYTHONIOENCODING n case of Encode/Decode error (when relevant - whatever it means, not always)

SylvainDe commented 7 years ago

http://python-notes.curiousefficiency.org/en/latest/python_concepts/import_traps.html#the-name-shadowing-trap

SylvainDe commented 7 years ago

TypeError: Cannot create a consistent method resolution... http://stackoverflow.com/questions/29214888/typeerror-cannot-create-a-consistent-method-resolution-order-mro

SylvainDe commented 7 years ago

https://mail.python.org/pipermail/python-ideas/2017-June/046025.html https://mail.python.org/pipermail/python-ideas/2017-June/045954.html

SylvainDe commented 7 years ago

Interesting thing already done : https://twitter.com/DRMacIver/status/912812300125577216?s=03 .

>>> sum(["a", "b", "c"], '')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: sum() can't sum strings [use ''.join(seq) instead]
SylvainDe commented 6 years ago
>>> set([42])[0]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'set' object does not support indexing

Maybe suggest pop ?

SylvainDe commented 6 years ago
>>> del s[42]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'set' object doesn't support item deletion
>>> s.remove(42)
>>> d = {43: 'x'}
>>> d.remove(43)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'dict' object has no attribute 'remove'
>>> del d[43]

(Also discard)

SylvainDe commented 6 years ago

https://mail.python.org/pipermail/python-ideas/2017-July/046318.html

SylvainDe commented 6 years ago

https://twitter.com/DRMacIver/status/949956253358452736

SylvainDe commented 5 years ago

https://blog.lerner.co.il/favorite-terrible-python-error-message/

See also: https://bugs.python.org/issue31506

SylvainDe commented 5 years ago

Add tests for walrus operator

SylvainDe commented 5 years ago

Add suggestion for keyerror. I thought this was tackled already but apparently no

https://realpython.com/python-keyerror/

SylvainDe commented 5 years ago

Positional only arguments

SylvainDe commented 5 years ago

https://inventwithpython.com/blog/2019/08/15/python-error-messages-gotta-catch-em-all/

SylvainDe commented 5 years ago

KeyError on del on a dict. Should call pop ?

SylvainDe commented 5 years ago

https://twitter.com/cfbolz/status/1168979340601831424?s=19

https://bitbucket.org/pypy/pypy/commits/c0b2526268ab96a0b3caa7bdafa2cf0309a73a20 https://bitbucket.org/pypy/pypy/commits/de78bcdc0fad5293211864bfabf3ad61e8780d6a https://bitbucket.org/pypy/pypy/commits/8cebeebbf0a7fb6c61aa65183f53392c68967fb3