/usr/lib/python3.10/__pycache__
NameSizeModeActions
abc.cpython-310.pyc67510644editdlrm
aifc.cpython-310.pyc246850644editdlrm
antigravity.cpython-310.pyc8220644editdlrm
argparse.cpython-310.pyc635390644editdlrm
ast.cpython-310.pyc557390644editdlrm
asynchat.cpython-310.pyc70250644editdlrm
asyncore.cpython-310.pyc160020644editdlrm
base64.cpython-310.pyc171620644editdlrm
bdb.cpython-310.pyc258320644editdlrm
binhex.cpython-310.pyc128700644editdlrm
bisect.cpython-310.pyc25880644editdlrm
bz2.cpython-310.pyc108700644editdlrm
calendar.cpython-310.pyc263030644editdlrm
cgi.cpython-310.pyc267230644editdlrm
cgitb.cpython-310.pyc99980644editdlrm
chunk.cpython-310.pyc48600644editdlrm
cmd.cpython-310.pyc127070644editdlrm
code.cpython-310.pyc99570644editdlrm
codecs.cpython-310.pyc332190644editdlrm
codeop.cpython-310.pyc55950644editdlrm
colorsys.cpython-310.pyc32650644editdlrm
compileall.cpython-310.pyc127330644editdlrm
configparser.cpython-310.pyc454580644editdlrm
contextlib.cpython-310.pyc208950644editdlrm
contextvars.cpython-310.pyc2460644editdlrm
copy.cpython-310.pyc69960644editdlrm
copyreg.cpython-310.pyc46830644editdlrm
cProfile.cpython-310.pyc51130644editdlrm
crypt.cpython-310.pyc35500644editdlrm
csv.cpython-310.pyc117980644editdlrm
dataclasses.cpython-310.pyc265780644editdlrm
datetime.cpython-310.pyc565330644editdlrm
decimal.cpython-310.pyc3620644editdlrm
difflib.cpython-310.pyc589050644editdlrm
dis.cpython-310.pyc156560644editdlrm
doctest.cpython-310.pyc761750644editdlrm
enum.cpython-310.pyc260630644editdlrm
filecmp.cpython-310.pyc87490644editdlrm
fileinput.cpython-310.pyc140720644editdlrm
fnmatch.cpython-310.pyc42440644editdlrm
fractions.cpython-310.pyc186000644editdlrm
ftplib.cpython-310.pyc290340644editdlrm
functools.cpython-310.pyc283350644editdlrm
genericpath.cpython-310.pyc39070644editdlrm
getopt.cpython-310.pyc63390644editdlrm
getpass.cpython-310.pyc42100644editdlrm
gettext.cpython-310.pyc182210644editdlrm
glob.cpython-310.pyc58520644editdlrm
graphlib.cpython-310.pyc76160644editdlrm
gzip.cpython-310.pyc185460644editdlrm
hashlib.cpython-310.pyc68450644editdlrm
heapq.cpython-310.pyc138650644editdlrm
hmac.cpython-310.pyc69730644editdlrm
imaplib.cpython-310.pyc423120644editdlrm
imghdr.cpython-310.pyc39050644editdlrm
imp.cpython-310.pyc97860644editdlrm
inspect.cpython-310.pyc851530644editdlrm
io.cpython-310.pyc36630644editdlrm
ipaddress.cpython-310.pyc626700644editdlrm
keyword.cpython-310.pyc9270644editdlrm
linecache.cpython-310.pyc41420644editdlrm
locale.cpython-310.pyc461540644editdlrm
lzma.cpython-310.pyc121000644editdlrm
mailbox.cpython-310.pyc600910644editdlrm
mailcap.cpython-310.pyc73200644editdlrm
mimetypes.cpython-310.pyc176190644editdlrm
modulefinder.cpython-310.pyc161660644editdlrm
netrc.cpython-310.pyc39330644editdlrm
nntplib.cpython-310.pyc316230644editdlrm
ntpath.cpython-310.pyc147040644editdlrm
nturl2path.cpython-310.pyc17470644editdlrm
numbers.cpython-310.pyc118660644editdlrm
opcode.cpython-310.pyc54470644editdlrm
operator.cpython-310.pyc135080644editdlrm
optparse.cpython-310.pyc477540644editdlrm
os.cpython-310.pyc315990644editdlrm
pathlib.cpython-310.pyc420520644editdlrm
pdb.cpython-310.pyc474400644editdlrm
pickle.cpython-310.pyc468820644editdlrm
pickletools.cpython-310.pyc677600644editdlrm
pipes.cpython-310.pyc77690644editdlrm
pkgutil.cpython-310.pyc183610644editdlrm
platform.cpython-310.pyc274290644editdlrm
plistlib.cpython-310.pyc237650644editdlrm
poplib.cpython-310.pyc135730644editdlrm
posixpath.cpython-310.pyc105600644editdlrm
pprint.cpython-310.pyc178750644editdlrm
profile.cpython-310.pyc143910644editdlrm
pstats.cpython-310.pyc236210644editdlrm
pty.cpython-310.pyc41430644editdlrm
pyclbr.cpython-310.pyc97750644editdlrm
pydoc.cpython-310.pyc856450644editdlrm
py_compile.cpython-310.pyc73390644editdlrm
queue.cpython-310.pyc107920644editdlrm
quopri.cpython-310.pyc57940644editdlrm
random.cpython-310.pyc227480644editdlrm
re.cpython-310.pyc142270644editdlrm
reprlib.cpython-310.pyc52500644editdlrm
rlcompleter.cpython-310.pyc59540644editdlrm
runpy.cpython-310.pyc94110644editdlrm
sched.cpython-310.pyc61150644editdlrm
secrets.cpython-310.pyc21750644editdlrm
selectors.cpython-310.pyc171050644editdlrm
shelve.cpython-310.pyc94920644editdlrm
shlex.cpython-310.pyc77820644editdlrm
shutil.cpython-310.pyc385360644editdlrm
signal.cpython-310.pyc29350644editdlrm
site.cpython-310.pyc179220644editdlrm
sitecustomize.cpython-310.pyc2250644editdlrm
smtpd.cpython-310.pyc261470644editdlrm
smtplib.cpython-310.pyc357660644editdlrm
sndhdr.cpython-310.pyc69620644editdlrm
socket.cpython-310.pyc289630644editdlrm
socketserver.cpython-310.pyc253470644editdlrm
sre_compile.cpython-310.pyc151940644editdlrm
sre_constants.cpython-310.pyc63570644editdlrm
sre_parse.cpython-310.pyc217550644editdlrm
ssl.cpython-310.pyc452710644editdlrm
stat.cpython-310.pyc42730644editdlrm
statistics.cpython-310.pyc370510644editdlrm
string.cpython-310.pyc71020644editdlrm
stringprep.cpython-310.pyc170750644editdlrm
struct.cpython-310.pyc3070644editdlrm
subprocess.cpython-310.pyc447410644editdlrm
sunau.cpython-310.pyc164820644editdlrm
symtable.cpython-310.pyc128350644editdlrm
sysconfig.cpython-310.pyc181510644editdlrm
tabnanny.cpython-310.pyc69500644editdlrm
tarfile.cpython-310.pyc715780644editdlrm
telnetlib.cpython-310.pyc185060644editdlrm
tempfile.cpython-310.pyc273390644editdlrm
textwrap.cpython-310.pyc138120644editdlrm
this.cpython-310.pyc12640644editdlrm
threading.cpython-310.pyc449690644editdlrm
timeit.cpython-310.pyc117690644editdlrm
token.cpython-310.pyc27380644editdlrm
tokenize.cpython-310.pyc171940644editdlrm
trace.cpython-310.pyc198700644editdlrm
traceback.cpython-310.pyc217120644editdlrm
tracemalloc.cpython-310.pyc175250644editdlrm
tty.cpython-310.pyc10790644editdlrm
turtle.cpython-310.pyc1288570644editdlrm
types.cpython-310.pyc95250644editdlrm
typing.cpython-310.pyc852770644editdlrm
uu.cpython-310.pyc38670644editdlrm
uuid.cpython-310.pyc224980644editdlrm
warnings.cpython-310.pyc136460644editdlrm
wave.cpython-310.pyc175940644editdlrm
weakref.cpython-310.pyc203430644editdlrm
webbrowser.cpython-310.pyc174630644editdlrm
xdrlib.cpython-310.pyc78800644editdlrm
zipapp.cpython-310.pyc60130644editdlrm
zipfile.cpython-310.pyc618450644editdlrm
zipimport.cpython-310.pyc170330644editdlrm
_aix_support.cpython-310.pyc28790644editdlrm
_bootsubprocess.cpython-310.pyc22940644editdlrm
_collections_abc.cpython-310.pyc329250644editdlrm
_compat_pickle.cpython-310.pyc58720644editdlrm
_compression.cpython-310.pyc45120644editdlrm
_distutils_system_mod.cpython-310.pyc54220644editdlrm
_markupbase.cpython-310.pyc75720644editdlrm
_osx_support.cpython-310.pyc115350644editdlrm
_pydecimal.cpython-310.pyc1577360644editdlrm
_pyio.cpython-310.pyc736540644editdlrm
_py_abc.cpython-310.pyc46830644editdlrm
_sitebuiltins.cpython-310.pyc35470644editdlrm
_strptime.cpython-310.pyc159450644editdlrm
_sysconfigdata__linux_x86_64-linux-gnu.cpython-310.pyc353850644editdlrm
_sysconfigdata__x86_64-linux-gnu.cpython-310.pyc353790644editdlrm
_threading_local.cpython-310.pyc65390644editdlrm
_weakrefset.cpython-310.pyc76080644editdlrm
__future__.cpython-310.pyc41310644editdlrm
__phello__.foo.cpython-310.pyc1300644editdlrm
Edit: /usr/lib/python3.10/__pycache__/fractions.cpython-310.pyc (18600B)
o 9jRn@sxdZddlmZddlZddlZddlZddlZddlZdgZej j Z ej j Z edejejBZGdddejZdS)z+Fraction, infinite-precision, real numbers.DecimalNFractionaC \A\s* # optional whitespace at the start, then (?P[-+]?) # an optional sign, then (?=\d|\.\d) # lookahead for digit or .digit (?P\d*) # numerator (possibly empty) (?: # followed by (?:/(?P\d+))? # an optional denominator | # or (?:\.(?P\d*))? # an optional fractional part (?:E(?P[-+]?\d+))? # and optional exponent ) \s*\Z # and optional whitespace to finish cseZdZdZdZdRddfdd Zed d Zed d Zd dZ dSddZ e ddZ e ddZ ddZddZddZddZeeej\ZZddZeeej\ZZd d!Zeeej\ZZd"d#Zeeej\Z Z!d$d%Z"ee"ej#\Z$Z%d&d'Z&ee&e'\Z(Z)d(d)Z*ee*ej+\Z,Z-d*d+Z.d,d-Z/d.d/Z0d0d1Z1d2d3Z2d4d5Z3d6d7Z4d8d9Z5dTd:d;Z6dd?Z8d@dAZ9dBdCZ:dDdEZ;dFdGZdLdMZ?dNdOZ@dPdQZAZBS)Ura]This class implements rational numbers. In the two-argument form of the constructor, Fraction(8, 6) will produce a rational number equivalent to 4/3. Both arguments must be Rational. The numerator defaults to 0 and the denominator defaults to 1 so that Fraction(3) == 3 and Fraction() == 0. Fractions can also be constructed from: - numeric strings similar to those accepted by the float constructor (for example, '-2.3' or '1e10') - strings of the form '123/456' - float and Decimal instances - other Rational instances (including integers)  _numerator _denominatorrNT _normalizec stt||}|durt|tur||_d|_|St|tj r*|j |_|j |_|St|t t fr;|\|_|_|St|trt|}|durOtd|t|dpVd}|d}|rdt|}n8d}|d}|rdt|}||t|}||9}|d } | rt| } | d kr|d| 9}n|d| 9}|d d kr| }n3td t|turt|urnnnt|tj rt|tj r|j |j |j |j }}ntd|d krtd||rt||} |d kr| } || }|| }||_||_|S)aConstructs a Rational. Takes a string like '3/2' or '1.5', another Rational instance, a numerator/denominator pair, or a float. Examples -------- >>> Fraction(10, -8) Fraction(-5, 4) >>> Fraction(Fraction(1, 7), 5) Fraction(1, 35) >>> Fraction(Fraction(1, 7), Fraction(2, 3)) Fraction(3, 14) >>> Fraction('314') Fraction(314, 1) >>> Fraction('-35/4') Fraction(-35, 4) >>> Fraction('3.1415') # conversion from numeric string Fraction(6283, 2000) >>> Fraction('-47e-2') # string may include a decimal exponent Fraction(-47, 100) >>> Fraction(1.47) # direct construction from float (exact conversion) Fraction(6620291452234629, 4503599627370496) >>> Fraction(2.25) Fraction(9, 4) >>> Fraction(Decimal('1.47')) Fraction(147, 100) Nz Invalid literal for Fraction: %rnum0denomdecimal exprsign-z2argument should be a string or a Rational instancez+both arguments should be Rational instanceszFraction(%s, 0))superr__new__typeintrr isinstancenumbersRational numerator denominatorfloatras_integer_ratiostr_RATIONAL_FORMATmatch ValueErrorgrouplen TypeErrorZeroDivisionErrormathgcd) clsrrr selfmr rscalerg __class__ /usr/lib/python3.10/fractions.pyr>sv                zFraction.__new__cCsDt|tjr ||St|tstd|j|t|jf||S)zConverts a finite float to a rational number, exactly. Beware that Fraction.from_float(0.3) != Fraction(3, 10). z.%s.from_float() only takes floats, not %r (%s))rrIntegralrr$__name__rr)r(fr/r/r0 from_floats   zFraction.from_floatcCsVddlm}t|tjr|t|}nt||s%td|j|t|jf|| S)zAConverts a finite Decimal instance to a rational number, exactly.rrz2%s.from_decimal() only takes Decimals, not %r (%s)) rrrrr1rr$r2rr)r(decrr/r/r0 from_decimals    zFraction.from_decimalcCs |j|jfS)zReturn the integer ratio as a tuple. Return a tuple of two integers, whose ratio is equal to the Fraction and with a positive denominator. rr)r/r/r0rs zFraction.as_integer_ratio@Bc Cs|dkrtd|j|krt|Sd\}}}}|j|j}} ||}|||} | |kr.n|||||| f\}}}}||||}}q|||} t|| ||| |} t||} t| |t| |krl| S| S)aWClosest Fraction to self with denominator at most max_denominator. >>> Fraction('3.141592653589793').limit_denominator(10) Fraction(22, 7) >>> Fraction('3.141592653589793').limit_denominator(100) Fraction(311, 99) >>> Fraction(4321, 8765).limit_denominator(10000) Fraction(4321, 8765) r z$max_denominator should be at least 1)rr r r)r!rrrabs) r)max_denominatorp0q0p1q1ndaq2kbound1bound2r/r/r0limit_denominators(      zFraction.limit_denominatorcC|jSN)rrAr/r/r0rzFraction.numeratorcCrGrH)rrIr/r/r0rrJzFraction.denominatorcCsd|jj|j|jfS)z repr(self)z %s(%s, %s))r.r2rrr7r/r/r0__repr__szFraction.__repr__cCs$|jdkr t|jSd|j|jfS)z str(self)r z%s/%s)rrrr7r/r/r0__str__ s  zFraction.__str__csTfdd}djd|_j|_fdd}djd|_j|_||fS)aGenerates forward and reverse operators given a purely-rational operator and a function from the operator module. Use this like: __op__, __rop__ = _operator_fallbacks(just_rational_op, operator.op) In general, we want to implement the arithmetic operations so that mixed-mode operations either call an implementation whose author knew about the types of both arguments, or convert both to the nearest built in type and do the operation there. In Fraction, that means that we define __add__ and __radd__ as: def __add__(self, other): # Both types have numerators/denominator attributes, # so do the operation directly if isinstance(other, (int, Fraction)): return Fraction(self.numerator * other.denominator + other.numerator * self.denominator, self.denominator * other.denominator) # float and complex don't have those operations, but we # know about those types, so special case them. elif isinstance(other, float): return float(self) + other elif isinstance(other, complex): return complex(self) + other # Let the other type take over. return NotImplemented def __radd__(self, other): # radd handles more types than add because there's # nothing left to fall back to. if isinstance(other, numbers.Rational): return Fraction(self.numerator * other.denominator + other.numerator * self.denominator, self.denominator * other.denominator) elif isinstance(other, Real): return float(other) + float(self) elif isinstance(other, Complex): return complex(other) + complex(self) return NotImplemented There are 5 different cases for a mixed-type addition on Fraction. I'll refer to all of the above code that doesn't refer to Fraction, float, or complex as "boilerplate". 'r' will be an instance of Fraction, which is a subtype of Rational (r : Fraction <: Rational), and b : B <: Complex. The first three involve 'r + b': 1. If B <: Fraction, int, float, or complex, we handle that specially, and all is well. 2. If Fraction falls back to the boilerplate code, and it were to return a value from __add__, we'd miss the possibility that B defines a more intelligent __radd__, so the boilerplate should return NotImplemented from __add__. In particular, we don't handle Rational here, even though we could get an exact answer, in case the other type wants to do something special. 3. If B <: Fraction, Python tries B.__radd__ before Fraction.__add__. This is ok, because it was implemented with knowledge of Fraction, so it can handle those instances before delegating to Real or Complex. The next two situations describe 'b + r'. We assume that b didn't know about Fraction in its implementation, and that it uses similar boilerplate code: 4. If B <: Rational, then __radd_ converts both to the builtin rational type (hey look, that's us) and proceeds. 5. Otherwise, __radd__ tries to find the nearest common base ABC, and fall back to its builtin type. Since this class doesn't subclass a concrete type, there's no implementation to fall back to, so we need to try as hard as possible to return an actual value, or the user will get a TypeError. csLt|ttfr ||St|trt||St|tr$t||StSrH)rrrrcomplexNotImplementedrAbfallback_operatormonomorphic_operatorr/r0forwardds   z-Fraction._operator_fallbacks..forward__csVt|tjr ||St|tjrt|t|St|tjr)t|t|StSrH)rrrRealrComplexrMrNrPrArQr/r0reverseps    z-Fraction._operator_fallbacks..reverse__r)r2__doc__)rSrRrTrYr/rQr0_operator_fallbackssP  zFraction._operator_fallbacksc Cs|j|j}}|j|j}}t||}|dkr't||||||ddS||}|||||}t||} | dkrHt|||ddSt|| ||| ddS)za + br Frrrr&r'r rArPnadanbdbr,stg2r/r/r0_add  z Fraction._addc Cs|j|j}}|j|j}}t||}|dkr't||||||ddS||}|||||}t||} | dkrHt|||ddSt|| ||| ddS)za - br Frr]r^r/r/r0_subrgz Fraction._subcCsz|j|j}}|j|j}}t||}|dkr ||}||}t||}|dkr2||}||}t||||ddS)za * br Frr])rArPr_r`rarbg1rer/r/r0_muls  z Fraction._mulc Cs|j|j}}|j|j}}t||}|dkr ||}||}t||}|dkr2||}||}||||}} | dkrF| | }} t|| ddS)za / br rFrr]) rArPr_r`rarbrirer?r@r/r/r0_divs  z Fraction._divcCs|j|j|j|jS)za // brrrOr/r/r0 _floordivszFraction._floordivcCs:|j|j}}t|j|||j\}}|t|||fS)z(a // b, a % b))rdivmodrr)rArPr`rbdivn_modr/r/r0_divmod szFraction._divmodcCs,|j|j}}t|j||j|||S)za % b)rrr)rArPr`rbr/r/r0_modsz Fraction._modcCst|tjrL|jdkrD|j}|dkrt|j||j|ddS|jdkr3t|j| |j| ddSt|j | |j | ddSt|t|St||S)za ** b If b is not an integer, the result will be a float or complex since roots are generally irrational. If b is an integer, the result will be rational. r rFr) rrrrrrrrr)rArPpowerr/r/r0__pow__s&        zFraction.__pow__cCs\|jdkr|jdkr||jSt|tjrt|j|j|S|jdkr(||jS|t|S)za ** br r) rrrrrrrrrrXr/r/r0__rpow__:s     zFraction.__rpow__cCst|j|jddS)z++a: Coerces a subclass instance to FractionFrrrrrIr/r/r0__pos__HszFraction.__pos__cCst|j |jddS)z-aFrrvrIr/r/r0__neg__LszFraction.__neg__cCstt|j|jddS)zabs(a)Fr)rr9rrrIr/r/r0__abs__PszFraction.__abs__cCs&|jdkr |j |j S|j|jS)ztrunc(a)rrrIr/r/r0 __trunc__Ts  zFraction.__trunc__cCs |j|jS)z math.floor(a)rlrIr/r/r0 __floor__[s zFraction.__floor__cCs|j |j S)z math.ceil(a)rlrIr/r/r0__ceil___szFraction.__ceil__cCs|dur-t|j|j\}}|d|jkr|S|d|jkr!|dS|ddkr)|S|dSdt|}|dkr@tt|||Stt|||S)z?round(self, ndigits) Rounds half toward even. Nr rr)rnrrr9rround)r)ndigitsfloor remaindershiftr/r/r0 __round__ds  zFraction.__round__cCsdz t|jdt}Wn tyt}Yn wttt|j|}|jdkr'|n| }|dkr0dS|S)z hash(self)r)powr_PyHASH_MODULUSr! _PyHASH_INFhashr9r)r)dinvhash_resultr/r/r0__hash__}s zFraction.__hash__cCst|tur|j|ko|jdkSt|tjr"|j|jko!|j|jkSt|tj r0|j dkr0|j }t|t rJt |s?t |rCd|kS|||kStS)za == br r)rrrrrrrrrrWimagrealrr&isnanisinfr4rNrOr/r/r0__eq__s     zFraction.__eq__cCsbt|tjr||j|j|j|jSt|tr/t |s"t |r'|d|S||| |St S)acHelper for comparison operators, for internal use only. Implement comparison between a Rational instance `self`, and either another Rational instance or a float `other`. If `other` is not a Rational instance or a float, return NotImplemented. `op` should be one of the six standard comparison operators. r) rrrrrrrrr&rrr4rN)r)otheropr/r/r0_richcmps    zFraction._richcmpcC||tjS)za < b)roperatorltrOr/r/r0__lt__zFraction.__lt__cCr)za > b)rrgtrOr/r/r0__gt__rzFraction.__gt__cCr)za <= b)rrlerOr/r/r0__le__rzFraction.__le__cCr)za >= b)rrgerOr/r/r0__ge__rzFraction.__ge__cCs t|jS)za != 0)boolrrIr/r/r0__bool__s zFraction.__bool__cCs|jt|ffSrH)r.rr7r/r/r0 __reduce__szFraction.__reduce__cC t|tkr|S||j|jSrHrrr.rrr7r/r/r0__copy__ zFraction.__copy__cCrrHr)r)memor/r/r0 __deepcopy__rzFraction.__deepcopy__)rN)r8rH)Cr2 __module__ __qualname__r[ __slots__r classmethodr4r6rrFpropertyrrrKrLr\rfradd__add____radd__rhsub__sub____rsub__rjmul__mul____rmul__rktruediv __truediv__ __rtruediv__rmfloordiv __floordiv__ __rfloordiv__rqrn __divmod__ __rdivmod__rrmod__mod____rmod__rtrurwrxryrzr{r|rrrrrrrrrrrr __classcell__r/r/r-r0r&shi   7  0 !)r[rrr&rrresys__all__ hash_infomodulusrinfrcompileVERBOSE IGNORECASErrrr/r/r/r0s