harfbuzz / packtab Goto Github PK
View Code? Open in Web Editor NEWUnicode (and other integer) table packer
License: Apache License 2.0
Unicode (and other integer) table packer
License: Apache License 2.0
It is preferable to use isinstance
rather than comparing type objects for identity. Also better to compare integers for equality rather than object identity โ the latter may work for small-magnitude integers, but it can give surprising results sometimes.
diff --git a/Lib/packTab/__init__.py b/Lib/packTab/__init__.py
index bbf1e7f..f687485 100644
--- a/Lib/packTab/__init__.py
+++ b/Lib/packTab/__init__.py
@@ -25,7 +25,7 @@ except ImportError:
class AutoMapping(collections.defaultdict):
_next = 0
def __missing__(self, key):
- assert type(key) is not int
+ assert not isinstance(key, int)
v = self._next
self._next = self._next + 1
self[key] = v
@@ -60,8 +60,8 @@ def pack_table(data, mapping=None, default=0):
# Set up mapping. See docstring.
if mapping is not None:
- assert (all(type(k) is int and type(v) is str for k,v in mapping.items()) or
- all(type(k) is str and type(v) is int for k,v in mapping.items()))
+ assert (all(isinstance(k, int) and isinstance(v, str) for k,v in mapping.items()) or
+ all(isinstance(k, str) and isinstance(v, int) for k,v in mapping.items()))
mapping2 = mapping.copy()
for k,v in mapping.items():
mapping2[v] = k
@@ -72,7 +72,7 @@ def pack_table(data, mapping=None, default=0):
# Set up data as a list.
if isinstance(data, dict):
- assert(all(type(k) is int and type(v) in (int, str) for k,v in data.items()))
+ assert(all(isinstance(k, int) and isinstance(v, (int, str)) for k,v in data.items()))
minK = min(dict.keys())
maxK = max(dict.keys())
assert minK >= 0
@@ -83,11 +83,11 @@ def pack_table(data, mapping=None, default=0):
del data2
# Convert all to integers
- assert (all(type(v) is int for v in data) or
- all(type(v) is str for v in data))
- if type(data[0]) is str:
+ assert (all(isinstance(v, int) for v in data) or
+ all(isinstance(v, str) for v in data))
+ if isinstance(data[0], str):
data = [mapping[v] for v in data]
- if type(default) is str:
+ if isinstance(default, str):
default = mapping[default]
return solve(data, default)
@@ -111,7 +111,7 @@ def binaryBitsFor(n):
>>> binaryBitsFor(100)
8
"""
- if n is 1: return 0
+ if n == 1: return 0
return 1 << ceil(log2(log2(n)))
bytesPerOp = 4
Would be handy for rustybuzz.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.