Open SylvainDe opened 8 years ago
A few ideas from http://migrateup.com/main-difference-python-3/ are interesting too.
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.
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/ ).
Principle of Least Astonishment and Python : http://lucumr.pocoo.org/2011/7/9/python-and-pola/ .
A few suggestions might make sense.
Confusing/interesting error messages here : https://www.reddit.com/r/Python/comments/4ivd2k/what_is_your_favorite_python_error_message/
I've just discovered the change about literal octals in Python 3. Might be interesting to have a suggestion.
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"
http://stackoverflow.com/questions/38147923/mixing-datetime-strptime-arguments/38215307 pretty common error: mixing argument of strptime
.
https://twitter.com/brandon_rhodes/status/781234730091941888
SyntaxError: if a = b:
and if a == b
https://twitter.com/cfbolz/status/783313503230844929 .
The whole twitter thread is interesting with links such as:
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)
>>> 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
>>> 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 :)
TypeError: unhashable instance
Maybe suggest how to make the instance hashable (on custom classes), maybe suggest hashable types (frozenset
, tuple
, etc).
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
This is an interesting issue and might deserve some suggestion : http://stackoverflow.com/questions/4545661/unicodedecodeerror-when-redirecting-to-file
TypeError: can only concatenate list (not "dict_keys") to list
TypeError: argument to reversed() must be a sequence
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.
Idea: detection (?) and suggestion for circular import.
Idea: reuse _moved_attributes
from https://github.com/benjaminp/six/blob/master/six.py (with proper attribution).
Idea: use gc.get_objects()
for various purposes (get_func_by_name
, get_type_by_name
, etc).
"TypeError: 'generator' object is not subscriptable" -> itertools.islice(my_generator, 5)
Set.remove keyerror set.discard
Suggest using PYTHONIOENCODING n case of Encode/Decode error (when relevant - whatever it means, not always)
TypeError: Cannot create a consistent method resolution... http://stackoverflow.com/questions/29214888/typeerror-cannot-create-a-consistent-method-resolution-order-mro
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]
>>> set([42])[0]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'set' object does not support indexing
Maybe suggest pop
?
>>> 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
)
Add tests for walrus operator
Add suggestion for keyerror. I thought this was tackled already but apparently no
Positional only arguments
KeyError on del on a dict. Should call pop ?
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
Maybe things from https://twitter.com/DrapsTV/status/660657599210266624 can be reused (maybe not).