Skip to content

Instantly share code, notes, and snippets.

@Gorialis
Last active December 9, 2018 17:03
Show Gist options
  • Save Gorialis/f14080c815619f2dd1e9f0e128ef3fb4 to your computer and use it in GitHub Desktop.
Save Gorialis/f14080c815619f2dd1e9f0e128ef3fb4 to your computer and use it in GitHub Desktop.
bikeshed+
# -*- coding: utf-8 -*-
"""
equality
~~~~~~~~
Functions for determining the equality of objects
:license: MIT (OSI Approved)
"""
# pylint: enable=print-statement, parameter-unpacking, unpacking-in-except, old-raise-syntax, backtick, long-suffix, old-ne-operator, old-octal-literal, import-star-module-level, non-ascii-bytes-literal, raw-checker-failed, bad-inline-option, locally-disabled, locally-enabled, file-ignored, suppressed-message, useless-suppression, deprecated-pragma, use-symbolic-message-instead, apply-builtin, basestring-builtin, buffer-builtin, cmp-builtin, coerce-builtin, execfile-builtin, file-builtin, long-builtin, raw_input-builtin, reduce-builtin, standarderror-builtin, unicode-builtin, xrange-builtin, coerce-method, delslice-method, getslice-method, setslice-method, no-absolute-import, old-division, dict-iter-method, dict-view-method, next-method-called, metaclass-assignment, indexing-exception, raising-string, reload-builtin, oct-method, hex-method, nonzero-method, cmp-method, input-builtin, round-builtin, intern-builtin, unichr-builtin, map-builtin-not-iterating, zip-builtin-not-iterating, range-builtin-not-iterating, filter-builtin-not-iterating, using-cmp-argument, eq-without-hash, div-method, idiv-method, rdiv-method, exception-message-attribute, invalid-str-codec, sys-max-int, bad-python3-import, deprecated-string-function, deprecated-str-translate-call, deprecated-itertools-function, deprecated-types-field, next-method-defined, dict-items-not-iterating, dict-keys-not-iterating, dict-values-not-iterating, deprecated-operator-function, deprecated-urllib-function, xreadlines-attribute, deprecated-sys-function, exception-escape, comprehension-escape, ungrouped-imports
import typing
def equals(a: object, b: object) -> bool:
"""
Returns whether two objects are equal or not
This is useful for when you want to tell if something is equal to something else
Usage
-----
.. codeblock:: python3
c = equals(a, b) # this does a == b
Parameters
----------
a : object
The first object, to be compared against the second object
b : object
The second object, to be compared against the first object
Returns
-------
bool
Whether the comparison evaluated to True or not
Yields
------
Nothing
Raises
------
SystemExit
If exit() is called in the comparison
See Also
--------
:meth:`not_equal`
Returns whether two objects are *not* equal, or not.
Note
----
..note::
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"""
try:
result: bool = a == b
except Exception:
return False
if result:
return True
else:
return False
equals: typing.Callable[[object, object], bool] = equals
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment