|
4 | 4 | # |
5 | 5 | # MIT License |
6 | 6 | # |
7 | | -# Copyright (c) 2011-2018 Michael Truog <mjtruog at protonmail dot com> |
| 7 | +# Copyright (c) 2011-2019 Michael Truog <mjtruog at protonmail dot com> |
8 | 8 | # |
9 | 9 | # Permission is hereby granted, free of charge, to any person obtaining a |
10 | 10 | # copy of this software and associated documentation files (the "Software"), |
@@ -371,6 +371,7 @@ def _blocked_attribute(self): |
371 | 371 | pop = popitem = setdefault = update = _blocked_attribute |
372 | 372 | def __new__(cls, *args, **kw): |
373 | 373 | # pylint: disable=unused-argument |
| 374 | + # pylint: disable=too-many-nested-blocks |
374 | 375 | new = dict.__new__(cls) |
375 | 376 | args_ = [] |
376 | 377 | for arg in args: |
@@ -485,8 +486,8 @@ def _binary_to_term(i, data): |
485 | 486 | i += 1 |
486 | 487 | if tag == _TAG_REFERENCE_EXT: |
487 | 488 | return (i, OtpErlangReference(node, id_value, creation)) |
488 | | - elif tag == _TAG_PORT_EXT: |
489 | | - return (i, OtpErlangPort(node, id_value, creation)) |
| 489 | + # tag == _TAG_PORT_EXT |
| 490 | + return (i, OtpErlangPort(node, id_value, creation)) |
490 | 491 | elif tag == _TAG_PID_EXT: |
491 | 492 | i, node = _binary_to_atom(i, data) |
492 | 493 | id_value = data[i:i + 4] |
@@ -569,8 +570,7 @@ def _binary_to_term(i, data): |
569 | 570 | return (i, True) |
570 | 571 | elif atom_name == b'false': |
571 | 572 | return (i, False) |
572 | | - else: |
573 | | - return (i, OtpErlangAtom(atom_name)) |
| 573 | + return (i, OtpErlangAtom(atom_name)) |
574 | 574 | elif tag == _TAG_MAP_EXT: |
575 | 575 | length = struct.unpack(b'>I', data[i:i + 4])[0] |
576 | 576 | i += 4 |
@@ -707,7 +707,7 @@ def _term_to_binary(term): |
707 | 707 | return _tuple_to_binary(term) |
708 | 708 | elif isinstance(term, bool): |
709 | 709 | return OtpErlangAtom(term and b'true' or b'false').binary() |
710 | | - elif isinstance(term, int) or isinstance(term, TypeLong): |
| 710 | + elif isinstance(term, (int, TypeLong)): |
711 | 711 | return _long_to_binary(term) |
712 | 712 | elif isinstance(term, float): |
713 | 713 | return _float_to_binary(term) |
@@ -781,14 +781,12 @@ def _dict_to_binary(term): |
781 | 781 | def _integer_to_binary(term): |
782 | 782 | if 0 <= term <= 255: |
783 | 783 | return b_chr(_TAG_SMALL_INTEGER_EXT) + b_chr(term) |
784 | | - else: |
785 | | - return b_chr(_TAG_INTEGER_EXT) + struct.pack(b'>i', term) |
| 784 | + return b_chr(_TAG_INTEGER_EXT) + struct.pack(b'>i', term) |
786 | 785 |
|
787 | 786 | def _long_to_binary(term): |
788 | 787 | if -2147483648 <= term <= 2147483647: |
789 | 788 | return _integer_to_binary(term) |
790 | | - else: |
791 | | - return _bignum_to_binary(term) |
| 789 | + return _bignum_to_binary(term) |
792 | 790 |
|
793 | 791 | def _bignum_to_binary(term): |
794 | 792 | bignum = abs(term) |
@@ -923,4 +921,3 @@ def consult(string_in): |
923 | 921 | list_out.append(character) |
924 | 922 | i += 1 |
925 | 923 | return eval(''.join(list_out)) |
926 | | - |
0 commit comments