Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d785c65

Browse files
wbolsterhynek
andauthored
Clean up some more Python 2-isms (#942)
- Reword and simplify a few docstrings. - Add back a test for 2-arg super() in property() definitions that was (accidentally?) dropped in #936. Co-authored-by: Hynek Schlawack <[email protected]>
1 parent e18b5f3 commit d785c65

File tree

5 files changed

+15
-12
lines changed

5 files changed

+15
-12
lines changed

docs/glossary.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ Glossary
8080
... assert 23 == d.method()
8181

8282
- Slotted classes must implement :meth:`__getstate__ <object.__getstate__>` and :meth:`__setstate__ <object.__setstate__>` to be serializable with `pickle` protocol 0 and 1.
83-
Therefore, ``attrs`` creates these methods automatically for ``slots=True`` classes (Python 2 uses protocol 0 by default).
83+
Therefore, ``attrs`` creates these methods automatically for ``slots=True`` classes.
8484

8585
.. note::
8686

docs/hashing.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Because according to the definition_ from the official Python docs, the returned
3232
It follows that the moment you (or ``attrs``) change the way equality is handled by implementing ``__eq__`` which is based on attribute values, this constraint is broken.
3333
For that reason Python 3 will make a class that has customized equality unhashable.
3434
Python 2 on the other hand will happily let you shoot your foot off.
35-
Unfortunately ``attrs`` currently mimics Python 2's behavior for backward compatibility reasons if you set ``hash=False``.
35+
Unfortunately, ``attrs`` still mimics (otherwise unsupported) Python 2's behavior for backward compatibility reasons if you set ``hash=False``.
3636

3737
The *correct way* to achieve hashing by id is to set ``@attr.s(eq=False)``.
3838
Setting ``@attr.s(hash=False)`` (which implies ``eq=True``) is almost certainly a *bug*.

src/attr/_compat.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@
2626

2727

2828
def just_warn(*args, **kw):
29-
"""
30-
We only warn on Python 3 because we are not aware of any concrete
31-
consequences of not setting the cell on Python 2.
32-
"""
3329
warnings.warn(
3430
"Running interpreter doesn't sufficiently support code object "
3531
"introspection. Some features like bare super() or accessing "

src/attr/validators.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,10 @@ def matches_re(regex, flags=0, func=None):
169169
:param regex: a regex string or precompiled pattern to match against
170170
:param int flags: flags that will be passed to the underlying re function
171171
(default 0)
172-
:param callable func: which underlying `re` function to call (options
173-
are `re.fullmatch`, `re.search`, `re.match`, default
174-
is ``None`` which means either `re.fullmatch` or an emulation of
175-
it on Python 2). For performance reasons, they won't be used directly
176-
but on a pre-`re.compile`\ ed pattern.
172+
:param callable func: which underlying `re` function to call. Valid options
173+
are `re.fullmatch`, `re.search`, and `re.match`; the default ``None``
174+
means `re.fullmatch`. For performance reasons, the pattern is always
175+
precompiled using `re.compile`.
177176
178177
.. versionadded:: 19.2.0
179178
.. versionchanged:: 21.3.0 *regex* can be a pre-compiled pattern.

tests/test_slots.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@ def test_getstate_set_state_force_true(self, cls):
690690

691691
def test_slots_super_property_get():
692692
"""
693-
On Python 2/3: the `super(self.__class__, self)` works.
693+
Both `super()` and `super(self.__class__, self)` work.
694694
"""
695695

696696
@attr.s(slots=True)
@@ -707,8 +707,16 @@ class B(A):
707707
def f(self):
708708
return super().f ** 2
709709

710+
@attr.s(slots=True)
711+
class C(A):
712+
@property
713+
def f(self):
714+
return super(C, self).f ** 2
715+
710716
assert B(11).f == 121
711717
assert B(17).f == 289
718+
assert C(11).f == 121
719+
assert C(17).f == 289
712720

713721

714722
def test_slots_super_property_get_shortcut():

0 commit comments

Comments
 (0)