updade from Atlas repo
This commit is contained in:
@@ -100,7 +100,7 @@ class Vector:
|
||||
def __repr__(self):
|
||||
components = reprlib.repr(self._components) # <3>
|
||||
components = components[components.find('['):-1] # <4>
|
||||
return 'Vector({})'.format(components)
|
||||
return f'Vector({components})'
|
||||
|
||||
def __str__(self):
|
||||
return str(tuple(self))
|
||||
@@ -113,7 +113,7 @@ class Vector:
|
||||
return tuple(self) == tuple(other)
|
||||
|
||||
def __abs__(self):
|
||||
return math.sqrt(sum(x * x for x in self)) # <6>
|
||||
return math.hypot(*self) # <6>
|
||||
|
||||
def __bool__(self):
|
||||
return bool(abs(self))
|
||||
|
||||
@@ -127,7 +127,7 @@ class Vector:
|
||||
def __repr__(self):
|
||||
components = reprlib.repr(self._components)
|
||||
components = components[components.find('['):-1]
|
||||
return 'Vector({})'.format(components)
|
||||
return f'Vector({components})'
|
||||
|
||||
def __str__(self):
|
||||
return str(tuple(self))
|
||||
@@ -140,7 +140,7 @@ class Vector:
|
||||
return tuple(self) == tuple(other)
|
||||
|
||||
def __abs__(self):
|
||||
return math.sqrt(sum(x * x for x in self))
|
||||
return math.hypot(*self)
|
||||
|
||||
def __bool__(self):
|
||||
return bool(abs(self))
|
||||
|
||||
@@ -170,7 +170,7 @@ class Vector:
|
||||
def __repr__(self):
|
||||
components = reprlib.repr(self._components)
|
||||
components = components[components.find('['):-1]
|
||||
return 'Vector({})'.format(components)
|
||||
return f'Vector({components})'
|
||||
|
||||
def __str__(self):
|
||||
return str(tuple(self))
|
||||
@@ -183,7 +183,7 @@ class Vector:
|
||||
return tuple(self) == tuple(other)
|
||||
|
||||
def __abs__(self):
|
||||
return math.sqrt(sum(x * x for x in self))
|
||||
return math.hypot(*self)
|
||||
|
||||
def __bool__(self):
|
||||
return bool(abs(self))
|
||||
@@ -207,8 +207,8 @@ class Vector:
|
||||
pos = cls.shortcut_names.find(name) # <3>
|
||||
if 0 <= pos < len(self._components): # <4>
|
||||
return self._components[pos]
|
||||
msg = '{.__name__!r} object has no attribute {!r}' # <5>
|
||||
raise AttributeError(msg.format(cls, name))
|
||||
msg = f'{cls.__name__!r} object has no attribute {name!r}' # <5>
|
||||
raise AttributeError(msg)
|
||||
# end::VECTOR_V3_GETATTR[]
|
||||
|
||||
# tag::VECTOR_V3_SETATTR[]
|
||||
@@ -216,7 +216,7 @@ class Vector:
|
||||
cls = type(self)
|
||||
if len(name) == 1: # <1>
|
||||
if name in cls.shortcut_names: # <2>
|
||||
error = 'readonly attribute {attr_name!r}'
|
||||
error = 'read-only attribute {attr_name!r}'
|
||||
elif name.islower(): # <3>
|
||||
error = "can't set attributes 'a' to 'z' in {cls_name!r}"
|
||||
else:
|
||||
|
||||
@@ -166,7 +166,7 @@ class Vector:
|
||||
def __repr__(self):
|
||||
components = reprlib.repr(self._components)
|
||||
components = components[components.find('['):-1]
|
||||
return 'Vector({})'.format(components)
|
||||
return f'Vector({components})'
|
||||
|
||||
def __str__(self):
|
||||
return str(tuple(self))
|
||||
@@ -184,7 +184,7 @@ class Vector:
|
||||
return functools.reduce(operator.xor, hashes, 0)
|
||||
|
||||
def __abs__(self):
|
||||
return math.sqrt(sum(x * x for x in self))
|
||||
return math.hypot(*self)
|
||||
|
||||
def __bool__(self):
|
||||
return bool(abs(self))
|
||||
@@ -207,8 +207,8 @@ class Vector:
|
||||
pos = cls.shortcut_names.find(name)
|
||||
if 0 <= pos < len(self._components):
|
||||
return self._components[pos]
|
||||
msg = '{.__name__!r} object has no attribute {!r}'
|
||||
raise AttributeError(msg.format(cls, name))
|
||||
msg = f'{cls.__name__!r} object has no attribute {name!r}'
|
||||
raise AttributeError(msg)
|
||||
|
||||
@classmethod
|
||||
def frombytes(cls, octets):
|
||||
|
||||
@@ -209,7 +209,7 @@ class Vector:
|
||||
def __repr__(self):
|
||||
components = reprlib.repr(self._components)
|
||||
components = components[components.find('['):-1]
|
||||
return 'Vector({})'.format(components)
|
||||
return f'Vector({components})'
|
||||
|
||||
def __str__(self):
|
||||
return str(tuple(self))
|
||||
@@ -227,7 +227,7 @@ class Vector:
|
||||
return functools.reduce(operator.xor, hashes, 0)
|
||||
|
||||
def __abs__(self):
|
||||
return math.sqrt(sum(x * x for x in self))
|
||||
return math.hypot(*self)
|
||||
|
||||
def __bool__(self):
|
||||
return bool(abs(self))
|
||||
@@ -250,11 +250,11 @@ class Vector:
|
||||
pos = cls.shortcut_names.find(name)
|
||||
if 0 <= pos < len(self._components):
|
||||
return self._components[pos]
|
||||
msg = '{.__name__!r} object has no attribute {!r}'
|
||||
raise AttributeError(msg.format(cls, name))
|
||||
msg = f'{cls.__name__!r} object has no attribute {name!r}'
|
||||
raise AttributeError(msg)
|
||||
|
||||
def angle(self, n): # <2>
|
||||
r = math.sqrt(sum(x * x for x in self[n:]))
|
||||
r = math.hypot(*self[n:])
|
||||
a = math.atan2(r, self[n-1])
|
||||
if (n == len(self) - 1) and (self[-1] < 0):
|
||||
return math.pi * 2 - a
|
||||
|
||||
Reference in New Issue
Block a user